home *** CD-ROM | disk | FTP | other *** search
- // This may look like C code, but it is really -*- C++ -*-
- /*
- ************************************************************************
- *
- * Grayscale Image
- *
- * The image is represented as a Pixmap, i.e. a matrix of pixels
- * each of them specifies the gray level at a particular point
- *
- * The header file defines arithmetical and all other operations
- * permitted on the grayscale image
- *
- * $Id: image.h,v 1.14 1994/03/24 20:40:21 oleg Exp oleg $
- *
- ************************************************************************
- */
-
- //#pragma once
- #ifndef _image_h
- #define _image_h
-
- #pragma interface
-
- #include "myenv.h"
- #include <std.h>
-
- typedef unsigned short GRAY; // Pixel type
- typedef signed short GRAY_SIGNED; // Pixel type, signed
- const int GRAY_MAXBIT = 8*sizeof(GRAY); // Max no of bits per pixel
- const int GRAY_MAXVAL = ((1<<GRAY_MAXBIT)-1);
-
-
- class Rectangle;
- class rowcol;
- class Extrema;
- class IMAGE_to_PASS;
- class EndianIO;
-
- typedef int USER_F(int); // User function that can be applied
- // to the image
-
- class IMAGE
- {
- friend class Rectangle;
- friend class Extrema;
-
- private: // Private part
- int valid_code; // Validation code
- enum { IMAGE_val_code = 577767 }; // Image validation code
- int ncols; // Image width in pixels
- int nrows; // Image height in pixels
- int npixels; // Total no of pixels in the image
- char * name; // Image name
- int bits_per_pixel; // Image depth
- GRAY ** scanrows; // scanrows[i] = &pixels[i,0]
- GRAY * pixels; // pixels[i,j] is the
- // pixel value at point (i,j)
- // Pixels are ordered in rows
-
- void allocate(const int nrows, const int ncols, const int depth);
-
- void _expand(const IMAGE& prototype); // Expand the prototype twice
- void _shrink(const IMAGE& prototype); // Shrink the prototype twice
-
- // The following functions create an
- // image from a particular file
- // format. They call allocate()
- // to allocate the image data and
- // then read the data. The functions
- // are private to an IMAGE(file_name)
- // constructor and should be used
- // only by it
- void read_xwd(EndianIO& file, const char verbose); // read an X Window dump
- void read_pgm(EndianIO& file, const char verbose);// read a Portable GrayMap
- void read_tiff(EndianIO& file, const char verbose); // read TIFF
-
- public: // Public interface
-
- // Constructors and destructors
- // Make a blank image
- IMAGE(const int nrows, const int ncols, const int depth);
- IMAGE(const IMAGE &image); // Make a new blank image like
- // Read an image from the file
- // Attempts to detect the file format
- IMAGE(const char * file_name,const char print_header_info = 0);
- IMAGE(const Rectangle& area); // Make an image from a square area
- // of another image
-
- // Construct an image applying a spec
- // operation to the prototype
- enum IMAGE_CREATORS_1op { Expand, Shrink };
- IMAGE(const IMAGE_CREATORS_1op op, const IMAGE& prototype);
-
- ~IMAGE();
-
- void is_valid() const
- { assure(valid_code == IMAGE_val_code,"Invalid image"); }
-
- // Status
- int q_nrows() const { return nrows; }
- int q_ncols() const { return ncols; }
- int q_depth() const { return bits_per_pixel; }
- int q_npixels() const { return npixels; }
- const char * q_name() const { return name; }
- void set_name(const char * new_name);
-
- // Individual pixel manipulations
- GRAY& operator () (const int row, const int col) const;
- GRAY& operator () (const rowcol pos) const;
- void sure_within(const rowcol pos) const; // Make sure the pos
- // is within the image
-
- // Row Column, Square operations
-
- // Image-scalar operations
-
- // Find out if the predicate
- // "(signed)pixel op val" is true for ALL
- // pixels of the image?
- int operator == (const int val) const; // ? (signed)pixels == val
- int operator != (const int val) const; // ? (signed)pixels != val
- int operator < (const int val) const; // ? (signed)pixels < val
- int operator <= (const int val) const; // ? (signed)pixels <= val
- int operator > (const int val) const; // ? (signed)pixels > val
- int operator >= (const int val) const; // ? (signed)pixels >= val
-
- // Modify every element of the
- // image according to the operation
- IMAGE& operator = (const int val); // Assignment to all the pixels
- IMAGE& operator -= (const int val); // Diminish the brightness
- IMAGE& operator += (const int val); // Increase the brightness
- IMAGE& operator *= (const int val);
- IMAGE& operator |= (const int val); // OR
- IMAGE& operator &= (const int val); //